unit UnitCliente;

interface

uses
  Windows, variants, Messages, SysUtils, Classes, clipbrd, Graphics, Controls, Forms, Dialogs,
  DBCtrls, StdCtrls, Mask, ExtCtrls, Db, DBTables, Buttons, Grids, DBGrids,
  ComCtrls, QuickRpt, ToolWin, ActnList;

type
    THackDBGrid = class(TDBGrid);

  Tfcliente = class(TForm)
    ActionList1: TActionList;
    novo: TAction;
    voltar: TAction;
    avancar: TAction;
    foco: TAction;
    formatar: TAction;
    formatarsql: TAction;
    desativar: TAction;
    fornecedor: TAction;
    consumonf: TAction;
    atualizarpreco: TAction;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    Panel2: TPanel;
    ScrollBox1: TScrollBox;
    ScrollBox2: TScrollBox;
    Bevel1: TBevel;
    Bevel2: TBevel;
    Bevel4: TBevel;
    Bevel3: TBevel;
    Label33: TLabel;
    Label32: TLabel;
    Label31: TLabel;
    Label30: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    Label4: TLabel;
    Label9: TLabel;
    Label14: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label17: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label10: TLabel;
    Label15: TLabel;
    Label11: TLabel;
    Label16: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Label28: TLabel;
    Label1: TLabel;
    Label34: TLabel;
    EditData: TDBEdit;
    EditCodigo: TDBEdit;
    EditNomeFntasia: TDBEdit;
    EditNome: TDBEdit;
    EditEndereco: TDBEdit;
    EditBairro: TDBEdit;
    EditCidade: TDBEdit;
    EditCEP: TDBEdit;
    EditCGC: TDBEdit;
    EditIE: TDBEdit;
    EditFone: TDBEdit;
    EditFoneFax: TDBEdit;
    EditContato: TDBEdit;
    EditCargoContato: TDBEdit;
    DBEdit4: TDBEdit;
    DBEdit6: TDBEdit;
    DBEdit10: TDBEdit;
    DBEdit9: TDBEdit;
    DBLookupComboBox2: TDBLookupComboBox;
    DBEdit12: TDBEdit;
    DBLookupComboBox3: TDBLookupComboBox;
    ScrollBox3: TScrollBox;
    DBGrid3: TDBGrid;
    Panel4: TPanel;
    Label26: TLabel;
    Edit2: TEdit;
    Panel1: TPanel;
    ToolBar2: TToolBar;
    Panel13: TPanel;
    Panel10: TPanel;
    btnPrimeiro: TSpeedButton;
    btnVoltar: TSpeedButton;
    btnAvancar: TSpeedButton;
    btnUltimo: TSpeedButton;
    Panel6: TPanel;
    Panel7: TPanel;
    btnnovo: TSpeedButton;
    Panel5: TPanel;
    btngravar: TSpeedButton;
    Panel12: TPanel;
    btncancelar: TSpeedButton;
    Panel8: TPanel;
    SpeedButton21: TSpeedButton;
    Panel11: TPanel;
    Panel3: TPanel;
    btnimprimir: TSpeedButton;
    Panel9: TPanel;
    Panel14: TPanel;
    SpeedButton23: TSpeedButton;
    Panel16: TPanel;
    SpeedButton1: TSpeedButton;
    Panel18: TPanel;
    TabSheet2: TTabSheet;
    GroupBox1: TGroupBox;
    Bevel11: TBevel;
    Bevel10: TBevel;
    Bevel5: TBevel;
    Bevel6: TBevel;
    Bevel7: TBevel;
    Bevel8: TBevel;
    Bevel9: TBevel;
    SpeedButton9: TSpeedButton;
    SpeedButton10: TSpeedButton;
    SpeedButton11: TSpeedButton;
    SpeedButton8: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton2: TSpeedButton;
    btcancelar: TSpeedButton;
    DBGrid1: TDBGrid;
    DBLookupComboBox4: TDBLookupComboBox;
    Label8: TLabel;
    DBEdit3: TDBEdit;
    Label18: TLabel;
    Label24: TLabel;
    StatusBar1: TStatusBar;
    Panel15: TPanel;
    Label19: TLabel;
    DBEdit1: TDBEdit;
    ajuda: TAction;
    Label20: TLabel;
    DBEdit2: TDBEdit;
    Label25: TLabel;
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure Label3Click(Sender: TObject);
    procedure Label4Click(Sender: TObject);
    procedure Label5Click(Sender: TObject);
    procedure Label6Click(Sender: TObject);
    procedure EditCGCExit(Sender: TObject);
    procedure SpeedButton12Click(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure SpeedButton8Click(Sender: TObject);
    procedure QRCompositeReport5AddReports(Sender: TObject);
    procedure btngravarClick(Sender: TObject);
    procedure btnnovoClick(Sender: TObject);
    procedure novoExecute(Sender: TObject);
    procedure btnPrimeiroClick(Sender: TObject);
    procedure btnVoltarClick(Sender: TObject);
    procedure btnAvancarClick(Sender: TObject);
    procedure btncancelarClick(Sender: TObject);
    procedure Label11Click(Sender: TObject);
    procedure SpeedButton21Click(Sender: TObject);
    procedure DBLookupComboBox1Click(Sender: TObject);
    procedure DBLookupComboBox2Click(Sender: TObject);
    procedure voltarExecute(Sender: TObject);
    procedure avancarExecute(Sender: TObject);
    procedure focoExecute(Sender: TObject);
    procedure formatarExecute(Sender: TObject);
    procedure EditDataKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditNomeFntasiaExit(Sender: TObject);
    procedure btnimprimirClick(Sender: TObject);
    procedure fornecedorExecute(Sender: TObject);
    procedure SpeedButton23Click(Sender: TObject);
    procedure EditCodigoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditNomeFntasiaKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditCGCKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditContatoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBLookupComboBox3Click(Sender: TObject);
    procedure btnUltimoClick(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure SpeedButton9Click(Sender: TObject);
    procedure SpeedButton10Click(Sender: TObject);
    procedure SpeedButton11Click(Sender: TObject);
    procedure btcancelarClick(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure Label10Click(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure formatarsqlExecute(Sender: TObject);
    procedure Edit2Exit(Sender: TObject);
    procedure ajudaExecute(Sender: TObject);
    procedure Label7Click(Sender: TObject);
  private
   FReport : TQuickRep;
   procedure AppHint(Sender : TObject);
    procedure SetReport(Value : TQuickRep);
  public
  ST, tipo:string;
  bok : boolean;
    property Report : TQuickRep read FReport write SetReport;
   { Private declarations }


  { Public declarations }
  end;

var
  fcliente: Tfcliente;
 Texto, Texto1 : String;
implementation

uses Unit1,UnitRelatorioCliente1, udm, UnitMenu;



procedure tfcliente.AppHint(Sender: TObject);
begin
  StatusBar1.Panels[0].Text := Application.Hint;
end;


{$R *.DFM}

procedure Tfcliente.SetReport(Value : TQuickRep);
begin
  FReport:=Value;
end;

procedure Tfcliente.FormKeyPress(Sender: TObject; var Key: Char);
begin
 if key=#13 then begin
  key := #0;
       Perform(WM_nextdlgctl,0,0);
 end Else if Key = #27 then
   Perform(WM_nextdlgctl,1,0);
end;

procedure Tfcliente.Label3Click(Sender: TObject);

begin

        BOK := inputquery('Localizar código','Entre com o código:',ST);
         if BOK then
          if not fdm.tbcliente.Locate ('Codigo',ST,[]) then
           ShowMessage ('Código não cadastrado !!!');
            ST := '';

end;

procedure Tfcliente.Label4Click(Sender: TObject);

Var
       Razao:String;
        LocCodogo : Boolean;
begin


     LocCodogo := InputQuery ('localizar', 'Entre com a Razão Social',Razao );
      if LocCodogo then begin
        if not fdm.tbcliente.FindKey ([Razao]) then
         ShowMessage ('Nome não encontrado');
          end;
end;

procedure Tfcliente.Label5Click(Sender: TObject);
begin
        BOK := inputquery('Localizar nome fantasia ou apelido','Entre com o nome:',ST);
         if BOK then
          if not fdm.tbcliente.Locate ('NomeFantasia',uppercase(ST),[]) then
           ShowMessage ('Nome não encontrado !!!');
            ST := '';

end;

procedure Tfcliente.Label6Click(Sender: TObject);


begin

        BOK := inputquery('Localizar CGC/CPF','Entre com os números:',ST);
         if BOK then
          if not fdm.tbcliente.Locate ('cgc',ST,[]) then
           ShowMessage ('Não localizado !!!');
            ST := '';

end;

procedure Tfcliente.EditCGCExit(Sender: TObject);
begin

            if length(EditCGC.Text) > 15 then
             if VerCGC(EditCGC.Text) = False then
              EditCGC.SetFocus;

             if length(EditCGC.Text) < 15 then
             if VerCPF(EditCGC.Text) = False then
              EditCGC.SetFocus;


end;

procedure Tfcliente.SpeedButton12Click(Sender: TObject);
begin
        fdm.tbcliente.Filtered := False;
end;

procedure Tfcliente.Edit2Change(Sender: TObject);
begin
        fdm.tbcliente.IndexFieldNames := 'nomefantasia';
         fdm.tbcliente.FindNearest([edit2.text]);

end;

procedure Tfcliente.SpeedButton8Click(Sender: TObject);

begin

   st:='';

   if fdm.query1['bairro'] <> null then
    st := fdm.query1['bairro'];

        BOK := inputquery('Filtrar Bairro','Entre com o nome do bairro, ou "T" para todos os bairros em ordem alfabética:',ST);
         if BOK then begin

        with fdm.query1 do begin
         close;
          sql.clear;
           if uppercase(st)='T' then
          sql.add ('select * from tbcliente order by bairro')
          else
           sql.add ('select * from tbcliente where bairro = "' + uppercase(st) + '"');
             open;

             end;
             THackDBGrid(DBGrid1).FixedCols := 9;
              end;

            tipo :='bairro';
                       formatarsqlexecute(self);

end;

procedure Tfcliente.QRCompositeReport5AddReports(Sender: TObject);
    begin;
end;

procedure Tfcliente.btngravarClick(Sender: TObject);
begin
         fdm.tbcliente.Edit;
          fdm.tbcliente.Post;
           btngravar.Enabled:=false;
            btncancelar.Enabled:=false;

end;

procedure Tfcliente.btnnovoClick(Sender: TObject);

begin
     novoexecute(self);
end;




procedure Tfcliente.novoExecute(Sender: TObject);
begin

       fdm.tbcliente.Refresh;


        with fdm.query1 do begin
         close;
          sql.clear;
           sql.add('select max(codigo) as codigo from tbcliente');
            open;
         end;

        fdm.tbcliente.insert;
        if fdm.query1['codigo'] <> null then
         fdm.tbcliente['codigo'] := fdm.query1['codigo'] + 1
        else
        fdm.tbcliente['codigo']:='1';
        fdm.tbcliente['data'] := datetostr(now);
        st := '';

        fdm.query1.close;

            editfone.setfocus;
                    btngravar.Enabled:=true;
                btncancelar.Enabled := true;





end;

procedure Tfcliente.btnPrimeiroClick(Sender: TObject);
begin
        fdm.tbcliente.first;
end;

procedure Tfcliente.btnVoltarClick(Sender: TObject);
begin
        fdm.tbcliente.prior;
end;

procedure Tfcliente.btnAvancarClick(Sender: TObject);
begin
        fdm.tbcliente.next;
end;

procedure Tfcliente.btncancelarClick(Sender: TObject);
begin
        fdm.tbcliente.cancel;
          btnGravar.Enabled:=false;
           btncancelar.enabled := false;
end;

procedure Tfcliente.Label11Click(Sender: TObject);
begin
        BOK := inputquery('Localizar contato','Entre com o nome do contato:',ST);
         if BOK then
          if not fdm.tbcliente.Locate ('Contato',uppercase(ST),[]) then
           ShowMessage ('Contato não localizado !!!');
            ST := '';
end;

procedure Tfcliente.SpeedButton21Click(Sender: TObject);
begin

          if Application.MessageBox('Deseja excluir este cliente? ',
         'Confirme', 4  + MB_ICONQUESTION)= idYes then begin

        fdm.tbcliente.delete;
          btnGravar.Enabled:=false;
           btncancelar.enabled := false;
        end;

end;

procedure Tfcliente.DBLookupComboBox1Click(Sender: TObject);
begin
        fdm.tbcliente.edit;
        fdm. tbcliente['comissaovendedor'] := fdm.tbvendedor['comissao'];
end;

procedure Tfcliente.DBLookupComboBox2Click(Sender: TObject);
begin
        fdm.tbcliente.edit;
         fdm.tbcliente['icm'] := fdm.tbestado['icm'];
          fdm.tbcliente['ipi'] := fdm.tbestado['ipi'];
end;

procedure Tfcliente.voltarExecute(Sender: TObject);
begin
        fdm.tbcliente.prior;
end;

procedure Tfcliente.avancarExecute(Sender: TObject);
begin
        fdm.tbcliente.next;
end;

procedure Tfcliente.focoExecute(Sender: TObject);
begin
        if not edit2.Focused then
        edit2.setfocus
        else
        editdata.setfocus;
end;

procedure Tfcliente.formatarExecute(Sender: TObject);
begin

 (fdm.tbcliente.fieldbyname ('codigo') as tfloatfield).displayformat := '000000';
  (fdm.tbcliente.fieldbyname ('cep') as tstringfield).editmask := '99.999-999';
   (fdm.tbcliente.fieldbyname ('fone') as tstringfield).editmask := '(99)9999-9999';
    (fdm.tbcliente.fieldbyname ('fone1') as tstringfield).editmask := '(99)9999-9999';
     (fdm.tbcliente.fieldbyname ('fonefax') as tstringfield).editmask := '(99)9999-9999';
      (fdm.tbcliente.fieldbyname ('uf') as tstringfield).editmask := 'aa';
       (fdm.tbcliente.fieldbyname ('nascimento') as tdatetimefield).editmask := '99/99/9999';
        (fdm.tbcliente.fieldbyname ('data') as tdatetimefield).editmask := '99/99/9999';
         (fdm.tbcliente.fieldbyname ('visita') as tdatetimefield).editmask := '99/99/9999';

end;

procedure Tfcliente.EditDataKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
        if key = 27 then dbgrid3.setfocus;
end;

procedure Tfcliente.EditNomeFntasiaExit(Sender: TObject);
begin
        if length(EditNomeFntasia.text) < 1 then begin
         showmessage('preencha o nome fantasia!!!');
           end;
end;

procedure Tfcliente.btnimprimirClick(Sender: TObject);
var
      bookmark : tbookmarkstr;
begin

           bookmark := fdm.tbcliente.Bookmark;

        application.CreateForm(tfrcliente, frcliente);

       fmenu.logotipoExecute(self);

  if fileexists (extractfilepath(paramstr(0)) + '\imagem\logo.bmp') then begin
  frcliente.image1.Picture.assign(clipboard);
  clipboard.clear;
  end;
  if fileexists (extractfilepath(paramstr(0)) + '\imagem\dado.txt') then
   frcliente.memo1.lines.loadfromfile(extractfilepath(paramstr(0)) + '\imagem\dado.txt');


       if fdm.tbcliente['NomeFantasia'] <> null then
        st := fdm.tbcliente['NomeFantasia'];

        if application.messagebox ('Deseja imprimir apenas este clientes?', 'Impressão', 4 + MB_ICONWARNING) =  mryes then begin

         fdm.tbcliente.Filter := 'nomefantasia = ''' + st + '''';
         fdm.tbcliente.Filtered := true;
         st := '';
         frcliente.quickficha.PreviewModal;
         fdm.tbcliente.Filtered := false
         end else begin

         fdm.tbcliente.IndexFieldNames := 'nomefantasia';
         frcliente.quickgrupo.PreviewModal;
         fdm.tbcliente.IndexFieldNames := '';
         end;

           frcliente.release;

              fdm.tbcliente.Bookmark  := bookmark;

end;

procedure Tfcliente.fornecedorExecute(Sender: TObject);
                                        
begin

          if Application.MessageBox('Deseja gerar fornecedor a partir  deste cadastro? ',
         'Confirme', 4 + MB_ICONINFORMATION)= idYes then begin

        fdm.tbfornecedor.Open;
        fdm.tbfornecedor.Last;

        with fdm.query1 do begin
         close;
          sql.clear;
           sql.add('select max(codigo) as codigo from tbfornecedor');
            open;
         end;


     fdm.tbfornecedor.Insert;

     fdm.tbfornecedor['Fantasia']:= fdm.tbcliente['NomeFantasia'] ;
     fdm.tbfornecedor['Fone_Fax'] :=fdm.tbcliente['FoneFax'] ;
     fdm.tbfornecedor['CGC'] :=fdm.tbcliente['CGC'] ;
     fdm.tbfornecedor['Data'] :=fdm.tbcliente['Data'] ;
     fdm.tbfornecedor['Fornecedor'] :=fdm.tbcliente['Nome'];
     fdm.tbfornecedor['uf'] :=fdm.tbcliente['UF'];
     fdm.tbfornecedor['Endereco']:=fdm.tbcliente['Endereco'] ;
     fdm.tbfornecedor['Bairro'] := fdm.tbcliente['Bairro'] ;
     fdm.tbfornecedor['Cidade'] := fdm.tbcliente['Cidade'] ;
     fdm.tbfornecedor['Cep'] :=fdm.tbcliente['Cep'];
     fdm.tbfornecedor['Contato'] := fdm.tbcliente['Contato'] ;
     fdm.tbfornecedor['CargoContato'] :=fdm.tbcliente['CargoContato'] ;
     fdm.tbfornecedor['Fone1'] :=fdm.tbcliente['Fone1'];
     fdm.tbfornecedor['Email']:= fdm.tbcliente['Email'];
     fdm.tbfornecedor['CondPgto']:= fdm.tbcliente['CondPgto'] ;
     fdm.tbfornecedor['Codigo'] := fdm.query1['codigo'] + 1;
     fdm.tbfornecedor.Post;
     fdm.tbfornecedor.Close;
     showmessage('Fornecedor Gerado');
     end;
     fdm.query1.close;


end;

procedure Tfcliente.SpeedButton23Click(Sender: TObject);
begin
        fornecedorexecute(self);
end;

procedure Tfcliente.EditCodigoKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
        if key = vk_f1 then
         label3click(self);
end;

procedure Tfcliente.EditNomeFntasiaKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
        if key = vk_f1 then
         label5click(self);
end;

procedure Tfcliente.EditCGCKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
                if key = vk_f1 then
         label6click(self);
end;

procedure Tfcliente.EditContatoKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
        if key = vk_f1 then
         label11click(self);
end;

procedure Tfcliente.DBLookupComboBox3Click(Sender: TObject);
begin
        fdm.tbcliente.Edit;
        fdm.tbcliente['parcelas'] := fdm.tbfatura['parcelas'];
end;

procedure Tfcliente.btnUltimoClick(Sender: TObject);
begin
        fdm.tbcliente.Last;
end;

procedure Tfcliente.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
        IF btngravar.Enabled = true then begin
         case application.MessageBox('Deseja salvar as alterações?', 'Sair de Cadastro de Cliente',mb_yesnocancel + MB_ICONQUESTION )of

         idyes : begin
         fdm.tbcliente.edit;
          fdm.tbcliente.post;
           canclose:=true;
            end;

         idno : begin
          fdm.tbcliente.cancel;
           canclose:=true;
            end;

         idcancel :
           canclose:=false;
end;
end;
end;

procedure Tfcliente.SpeedButton9Click(Sender: TObject);
begin
       st:='';

       IF fdm.query1['vendedor']<> null then
        st := fdm.query1['vendedor'];

        if inputquery('Filtrar Vendedor','Entre com o nome do vendedor, ou "T" para todos os vendedores em ordem alfabética:',st) then begin

        with fdm.query1 do begin
         close;
          sql.clear;
           if uppercase(st)='T' then
          sql.add ('select * from tbcliente order by vendedor')
          else
           sql.add ('select * from tbcliente where vendedor ="' + uppercase(st) + '" order by vendedor');
            open;
              end;
          THackDBGrid(DBGrid1).FixedCols := 9;
          tipo :='vendedor';
        end;
                      formatarsqlexecute(self);

end;

procedure Tfcliente.SpeedButton10Click(Sender: TObject);
begin

       st:='';
       IF fdm.query1['cidade']<> null then
        st := fdm.query1['cidade'];

        if inputquery('Filtrar Cidade','Entre com o nome da cidade, ou "T" para todas as cidades em ordem alfabética:',st) then begin

        with fdm.query1 do begin
         close;
          sql.clear;
           if uppercase(st)= 'T' then
          sql.add ('select * from tbcliente order by cidade')
          else
           sql.add ('select * from tbcliente where Cidade ="' + uppercase(st) + '" order by Cidade');
            open;
             end;

          tipo := 'cidade';
          THackDBGrid(DBGrid1).FixedCols := 9;
        end;
                      formatarsqlexecute(self);

end;

procedure Tfcliente.SpeedButton11Click(Sender: TObject);
begin

      st:='';
       IF fdm.query1['uf']<> null then
        st := fdm.query1['uf'];

        if inputquery('Filtrar Estado','Entre com a sigla do estado, ou "T" para todos os estados em ordem alfabética:',st) then begin

        with fdm.query1 do begin
         close;
          sql.clear;
          if uppercase(st)='T' then
          sql.add ('select * from tbcliente order by uf')
          else
           sql.add ('select * from tbcliente where uf ="' + uppercase(st) + '" order by uf');
            open;
             end;

          tipo := 'estado';
          THackDBGrid(DBGrid1).FixedCols := 9;
        end;
           formatarsqlexecute(self);

end;

procedure Tfcliente.btcancelarClick(Sender: TObject);
begin
         with fdm.query1 do begin
         close;
          sql.clear;
           sql.add ('select * from tbcliente order by bairro');
            open;
             end;
             tipo := 'bairro';
                        formatarsqlexecute(self);
               THackDBGrid(DBGrid1).FixedCols := 9;
end;

procedure Tfcliente.SpeedButton5Click(Sender: TObject);
begin

  fmenu.logotipoExecute(self);

        application.CreateForm(tfrcliente, frcliente);

  if (tipo = 'estado') then begin

  if fileexists (extractfilepath(paramstr(0)) + '\imagem\logo.bmp') then begin
  frcliente.image2.Picture.assign(clipboard);
  clipboard.clear;
  end;
  if fileexists (extractfilepath(paramstr(0)) + '\imagem\dado.txt') then
  frcliente.memo2.lines.loadfromfile(extractfilepath(paramstr(0)) + '\imagem\dado.txt');

  frcliente.quickestado.PreviewModal;
  end else


  if (tipo = 'cidade') then begin

  if fileexists (extractfilepath(paramstr(0)) + '\imagem\logo.bmp') then begin
  frcliente.image3.Picture.assign(clipboard);
  clipboard.clear;
  end;
  if fileexists (extractfilepath(paramstr(0)) + '\imagem\dado.txt') then
  frcliente.memo3.lines.loadfromfile(extractfilepath(paramstr(0)) + '\imagem\dado.txt');

  frcliente.quickcidade.PreviewModal;
  end else

  if (tipo = 'bairro') then begin

  if fileexists (extractfilepath(paramstr(0)) + '\imagem\logo.bmp') then begin
  frcliente.image4.Picture.assign(clipboard);
  clipboard.clear;
  end;
  if fileexists (extractfilepath(paramstr(0)) + '\imagem\dado.txt') then
  frcliente.memo4.lines.loadfromfile(extractfilepath(paramstr(0)) + '\imagem\dado.txt');

  frcliente.quickbairro.PreviewModal;
  end else

  if (tipo = 'vendedor') then begin

  if fileexists (extractfilepath(paramstr(0)) + '\imagem\logo.bmp') then begin
  frcliente.image5.Picture.assign(clipboard);
  clipboard.clear;
  end;
  if fileexists (extractfilepath(paramstr(0)) + '\imagem\dado.txt') then
  frcliente.memo5.lines.loadfromfile(extractfilepath(paramstr(0)) + '\imagem\dado.txt');

  frcliente.quickvendedor.PreviewModal;
  end;

     frcliente.release;

end;

procedure Tfcliente.SpeedButton2Click(Sender: TObject);
begin
        application.CreateForm(tfrcliente, frcliente);
         frcliente.Quicketiqueta.PreviewModal;
          frcliente.Release;
end;

procedure Tfcliente.SpeedButton1Click(Sender: TObject);
var
MSG: STRING;
begin

   st := '';

   if fdm.tbcliente['nomefantasia'] <> null then
    st := fdm.tbcliente['nomefantasia'];

    with fdm.query1 do begin
     close;
      sql.clear;
       sql.add ('select distinct nome from tbpedidoitem where operacao ="P" and fantasia = "'+ st+'"');
        open;
         end;

    while not fdm.query1.Eof do begin
    if fdm.query1['nome'] <> null then
    msg := msg + fdm.query1['nome']+ #13;
    fdm.query1.next;
    end;



    showmessage('PRODUTOS CONSUMIDOS:' + #13 + #13 + msg);



end;

procedure Tfcliente.FormActivate(Sender: TObject);
begin
        THackDBGrid(DBGrid3).FixedCols := 2;
         THackDBGrid(DBGrid1).FixedCols := 9;
end;

procedure Tfcliente.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  

	        Application.OnHint := nil;
end;

procedure Tfcliente.FormCreate(Sender: TObject);
begin
     Application.OnHint := AppHint;
end;

procedure Tfcliente.Label10Click(Sender: TObject);
begin
        BOK := inputquery('Localizar Telefone','Entre com o telefone:',ST);
         if BOK then
          if not fdm.tbcliente.Locate ('fone',ST,[]) then
           ShowMessage ('Telefone não cadastrado !!!');
            ST := '';
end;

procedure Tfcliente.PageControl1Change(Sender: TObject);
begin

               if pagecontrol1.ActivePageIndex = 0 then
        fdm.Query1.Close
       else begin


        with fdm.query1 do begin
         close;
          sql.clear;
           sql.add ('select * from tbcliente order by bairro');
            open;
             end;

             formatarsqlexecute(self);
             THackDBGrid(DBGrid1).FixedCols := 9;
             tipo := 'bairro';
              end;

end;

procedure Tfcliente.formatarsqlExecute(Sender: TObject);
begin
(fdm.query1.fieldbyname ('codigo') as tfloatfield).displayformat := '000000';
(fdm.query1.fieldbyname ('fone') as tstringfield).editmask := '(99)9999-9999';
end;

procedure Tfcliente.Edit2Exit(Sender: TObject);
begin
        fdm.tbcliente.IndexFieldNames := '';
end;

procedure Tfcliente.ajudaExecute(Sender: TObject);
var
  Comp: Trichedit; // * variável Comp da classe TMemo
  texto : string;
begin
  Comp := Trichedit.Create (Self);  // * cria o componente Memo
  Comp.Parent := Self;    // * exibe o componente criado

  if fileexists (extractfilepath(paramstr(0)) + '\ajuda\ajudacliente.txt') then
   comp.lines.loadfromfile (extractfilepath(paramstr(0)) + '\ajuda\ajudacliente.txt');

  texto := comp.Text;
  comp.Destroy;

  Showmessage (texto);


end;

procedure Tfcliente.Label7Click(Sender: TObject);
begin
        BOK := inputquery('Localizar nome RG/IE','Entre com os números:',ST);
         if BOK then
          if not fdm.tbcliente.Locate ('ie',ST,[]) then
           ShowMessage ('Não encontrado !!!');
            ST := '';

end;

end.
